<?php
/**
 * 类名称
 * User: 13651
 * Time: 2025/9/19 10:07
 */

namespace App\Repository;

use App\Models\LeshuaUnionBank;

class LeshuaUnionBankRepo extends CommonRepo
{
    /**
     * 数据入库
     * @param array $data
     * @param int $id
     * @return bool
     */
    public function saveData(array $data,int $id=0)
    {
        if ($id) {
            $result  = LeshuaUnionBank::query()->find($id);
        } else {
            $result = new LeshuaUnionBank();
        }
        if (empty($result))
            return 0;
        collect($data)->map(function ($val, $field) use ($result) {
            $result->{$field} = $val;
        });
        return $result->save() ? $result->id : 0;
    }

    /**
     * 根据名称获取银行编码
     * @param string $name
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
    public function getName(string $name)
    {
        return LeshuaUnionBank::query()->where('name', $name)->get();
    }
}